package com.oak.broke.exception.handler;

import com.oak.broke.exception.VipException;
import com.oak.broke.utils.MessageUtil;
import com.oak.broke.model.vip.base.ResponseMessage;
import lombok.extern.slf4j.Slf4j;
import org.springframework.core.annotation.Order;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @author tanghan
 * @Description 自定义会员异常处理
 * @date 2023/04/13/ 11:17:00
 */
@Slf4j
@RestControllerAdvice
@Order(1)
public class VipExceptionHandler {

    @ExceptionHandler(VipException.class)
    public ResponseMessage handleVipException(VipException vipException) {
        Integer code = vipException.getCode();
        String msg = MessageUtil.getMessage(code, vipException.getMsg());
        log.error("业务处理异常，原因:{}，堆栈信息:", msg, vipException);
        return ResponseMessage.fail(code, msg);
    }
}
